<?php use_stylesheets_for_form($form) ?>
<?php use_javascripts_for_form($form) ?>
<?php use_helper('jQuery')?>

<div id="main_header" class="ui-widget-header ui-corner-all">
    <?php if($form->getObject()->exists()):?>
        <h3>Editando Sección: "<?php echo $form->getObject()->getTitle() ?>"</h3>
    <?php else: ?>
        <h3>Nueva Sección de tipo "<?php echo $form->getObject()->getType() ?>"</h3>
    <?php endif; ?>
</div>
<div id="main_content" class="ui-widget ui-widget-content ui-corner-all">
    <div class="form">
        <?php if($form->getObject()->getIsSubsection()):?>
            <?php if ($form->getObject()->isNew()): ?>
                <?php echo jq_form_remote_tag(
                        array (
                            'update' => 'main',
                            'url'    => url_for('section_createsubsection',$section),
                            'before'   => 'hideMainContent();showLoaderMain();',
                            'complete' => 'hideLoader();showMainContent();',
                            'script'   => true
                        )) ?>
            <?php else: ?>
                <?php echo jq_form_remote_tag(
                        array (
                            'update' => 'main',
                            'url'    => url_for('section_update',$form->getObject()),
                            'before'   => 'hideMainContent();showLoaderMain();',
                            'complete' => 'hideLoader();showMainContent();',
                            'script'   => true
                        )) ?>
                <input type="hidden" name="sf_method" value="put" />
            <?php endif; ?>
        <?php else: ?>
            <?php if ($form->getObject()->isNew()): ?>
                <?php echo jq_form_remote_tag(
                        array (
                            'update' => 'main',
                            'url'    => url_for('section_createsection',$portal).'?type='.$type,
                            'before'   => 'hideMainContent();showLoaderMain();',
                            'complete' => 'hideLoader();showMainContent();',
                            'script'   => true
                        )) ?>
            <?php else: ?>
                <?php echo jq_form_remote_tag(
                        array (
                            'update' => 'main',
                            'url'    => url_for('section_update',$form->getObject()),
                            'before'   => 'hideMainContent();showLoaderMain();',
                            'complete' => 'hideLoader();showMainContent();',
                            'script'   => true
                        )) ?>
                <input type="hidden" name="sf_method" value="put" />
            <?php endif; ?>
        <?php endif; ?>
            <fieldset>
                <?php echo $form->renderHiddenFields() ?>
                <?php echo $form->renderGlobalErrors() ?>
                <div class="form-row first-row">
                    <?php echo $form['title']->renderLabel() ?>
                    <div class="form-field">
                        <?php echo $form['title']->renderError() ?>
                        <?php echo $form['title']->render() ?>
                    </div>
                </div>
                <div class="form-row">
                    <?php echo $form['uses_header']->renderLabel() ?>
                    <div class="form-field">
                        <?php echo $form['uses_header']->renderError() ?>
                        <?php echo $form['uses_header']->render() ?>
                    </div>
                </div>
                <div class="form-row">
                    <?php echo $form['uses_footer']->renderLabel() ?>
                    <div class="form-field">
                        <?php echo $form['uses_footer']->renderError() ?>
                        <?php echo $form['uses_footer']->render() ?>
                    </div>
                </div>
                <div class="form-row">
                    <?php echo $form['max_contents_per_page']->renderLabel() ?>
                    <div class="form-field">
                        <?php echo $form['max_contents_per_page']->renderError() ?>
                        <?php echo $form['max_contents_per_page']->render() ?>
                    </div>
                </div>
                <div class="form-row">
                    <?php echo $form['News']['uses_external_feed']->renderLabel() ?>
                    <div class="form-field">
                        <?php echo $form['News']['uses_external_feed']->renderError() ?>
                        <?php echo $form['News']['uses_external_feed']->render() ?>
                    </div>
                </div>
                <div class="form-row">
                    <?php echo $form['News']['webservice_feed_url']->renderLabel() ?>
                    <div class="form-field">
                        <?php echo $form['News']['webservice_feed_url']->renderError() ?>
                        <?php echo $form['News']['webservice_feed_url']->render() ?>
                    </div>
                </div>
                <div class="form-row">
                    <?php echo $form['News']['webservice_retrieve_url']->renderLabel() ?>
                    <div class="form-field">
                        <?php echo $form['News']['webservice_retrieve_url']->renderError() ?>
                        <?php echo $form['News']['webservice_retrieve_url']->render() ?>
                    </div>
                </div>
                <?php if(isset ($form['published']) ):?>
                    <div class="form-row">
                        <?php echo $form['published']->renderLabel() ?>
                        <div class="form-field">
                            <?php echo $form['published']->renderError() ?>
                            <?php echo $form['published']->render() ?>
                        </div>
                    </div>
                <?php endif;?>
                <?php if(isset ($form['is_enabled'])):?>
                    <div class="form-row">
                        <?php echo $form['is_enabled']->renderLabel() ?>
                        <div class="form-field">
                            <?php echo $form['is_enabled']->renderError() ?>
                            <?php echo $form['is_enabled']->render() ?>
                        </div>
                    </div>
                <?php endif;?>
            </fieldset>
            <div id="form_buttons" class="ui-widget">
                <input class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only ui-button-text"
                       type="submit" value="Guardar" title="Guardar"/>
                <?php if($form->getObject()->isNew()):?>
                    <?php if($form->getObject()->getIsSubsection()): ?>
                        <?php echo jq_link_to_remote(
                                '<span class="ui-button-text">Cancelar</span>',
                            array(
                                'update' => 'main',
                                'url' => url_for('section_show', $form->getObject()->getParent()),
                                'before' => '$("#editor_content").empty();'
                            ),
                            array(
                                'class' => 'ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only',
                                'title' => 'Cancelar'))
                        ?>
                    <?php else: ?>
                        <?php echo jq_link_to_remote(
                                '<span class="ui-button-text">Cancelar</span>',
                            array(
                                'update' => 'main',
                                'url' => url_for('portal_show', $form->getObject()->getPortal()),
                                'before' => '$("#editor_content").empty();'
                            ),
                            array(
                                'class' => 'ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only',
                                'title' => 'Cancelar'))
                        ?>
                    <?php endif;?>
                <?php else: ?>
                    <?php echo jq_link_to_remote(
                            '<span class="ui-button-text">Cancelar</span>',
                        array(
                            'update' => 'main',
                            'url' => url_for('section_show', $form->getObject()),
                            'before' => '$("#editor_content").empty();'
                        ),
                        array(
                            'class' => 'ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only',
                            'title' => 'Cancelar'))
                    ?>
                <?php endif; ?>
            </div>
        </form>
    </div>
</div>